#!/bin/bash

# 快速修复noVNC网络冲突

echo "🔧 快速修复noVNC网络冲突..."

# 1. 停止所有相关容器
echo "1. 停止所有相关容器..."
docker-compose -f docker-compose-novnc.yml down 2>/dev/null || true
docker-compose -f docker-compose.lightweight.yml down 2>/dev/null || true
docker-compose -f docker-compose.yml down 2>/dev/null || true

# 2. 删除冲突的网络
echo "2. 删除冲突的网络..."
docker network rm ubuntu-desktop_desktop-network-novnc 2>/dev/null || true
docker network rm ubuntu-desktop_desktop-network-lightweight 2>/dev/null || true
docker network rm ubuntu-desktop_desktop-network-standard 2>/dev/null || true
docker network rm desktop-network-novnc 2>/dev/null || true
docker network rm desktop-network-lightweight 2>/dev/null || true
docker network rm desktop-network-standard 2>/dev/null || true

# 3. 清理Docker网络
echo "3. 清理Docker网络..."
docker network prune -f

# 4. 检查并删除所有可能的冲突网络
echo "4. 检查并删除所有可能的冲突网络..."
docker network ls | grep -E "(desktop|172\.2[0-9])" | awk '{print $1}' | xargs -r docker network rm

# 5. 显示当前网络状态
echo "5. 当前网络状态："
docker network ls

echo "✅ 网络冲突修复完成！"
echo "现在可以重新启动noVNC服务："
echo "  ./start-novnc.sh" 